﻿using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace Studio
{
	// Token: 0x02000496 RID: 1174
	public class OCIItem : ObjectCtrlInfo
	{
		// Token: 0x17000308 RID: 776
		// (get) Token: 0x06001D39 RID: 7481 RVA: 0x000BA404 File Offset: 0x000B8604
		public OIItemInfo itemInfo
		{
			get
			{
				return this.objectInfo as OIItemInfo;
			}
		}

		// Token: 0x17000309 RID: 777
		// (get) Token: 0x06001D3A RID: 7482 RVA: 0x000BA414 File Offset: 0x000B8614
		public bool isAnime
		{
			get
			{
				return this.animator != null && this.animator.enabled;
			}
		}

		// Token: 0x1700030A RID: 778
		// (get) Token: 0x06001D3B RID: 7483 RVA: 0x000BA438 File Offset: 0x000B8638
		public bool isChangeColor
		{
			get
			{
				return !this.colorTargets.IsNullOrEmpty<OCIItem.ColorTargetInfo>();
			}
		}

		// Token: 0x1700030B RID: 779
		// (get) Token: 0x06001D3C RID: 7484 RVA: 0x000BA448 File Offset: 0x000B8648
		public bool isColor2
		{
			get
			{
				bool result;
				if (this.colorTargets.IsNullOrEmpty<OCIItem.ColorTargetInfo>())
				{
					result = false;
				}
				else
				{
					result = this.colorTargets.Any((OCIItem.ColorTargetInfo v) => v.isColor2 || v.isColor2Only);
				}
				return result;
			}
		}

		// Token: 0x1700030C RID: 780
		// (get) Token: 0x06001D3D RID: 7485 RVA: 0x000BA488 File Offset: 0x000B8688
		public bool isFK
		{
			get
			{
				return !this.listBones.IsNullOrEmpty<OCIChar.BoneInfo>();
			}
		}

		// Token: 0x1700030D RID: 781
		// (get) Token: 0x06001D3E RID: 7486 RVA: 0x000BA498 File Offset: 0x000B8698
		// (set) Token: 0x06001D3F RID: 7487 RVA: 0x000BA4A0 File Offset: 0x000B86A0
		public bool visible
		{
			get
			{
				return this.m_Visible;
			}
			set
			{
				this.m_Visible = value;
				for (int i = 0; i < this.arrayRender.Length; i++)
				{
					this.arrayRender[i].enabled = value;
				}
				if (!this.arrayParticle.IsNullOrEmpty<ParticleSystem>())
				{
					for (int j = 0; j < this.arrayParticle.Length; j++)
					{
						if (value)
						{
							this.arrayParticle[j].Play();
						}
						else
						{
							this.arrayParticle[j].Pause();
						}
					}
				}
			}
		}

		// Token: 0x06001D40 RID: 7488 RVA: 0x000BA52C File Offset: 0x000B872C
		public override void OnDelete()
		{
			if (!this.listBones.IsNullOrEmpty<OCIChar.BoneInfo>())
			{
				foreach (OCIChar.BoneInfo boneInfo in this.listBones)
				{
					Singleton<GuideObjectManager>.Instance.Delete(boneInfo.guideObject, true);
				}
				this.listBones.Clear();
			}
			Singleton<GuideObjectManager>.Instance.Delete(this.guideObject, true);
			UnityEngine.Object.Destroy(this.objectItem);
			if (this.parentInfo != null)
			{
				this.parentInfo.OnDetachChild(this);
			}
			Studio.DeleteInfo(this.objectInfo, true);
		}

		// Token: 0x06001D41 RID: 7489 RVA: 0x000BA5EC File Offset: 0x000B87EC
		public override void OnAttach(TreeNodeObject _parent, ObjectCtrlInfo _child)
		{
			if (_child.parentInfo == null)
			{
				Studio.DeleteInfo(_child.objectInfo, false);
			}
			else
			{
				_child.parentInfo.OnDetachChild(_child);
			}
			if (!this.itemInfo.child.Contains(_child.objectInfo))
			{
				this.itemInfo.child.Add(_child.objectInfo);
			}
			_child.guideObject.transformTarget.SetParent(this.childRoot);
			_child.guideObject.parent = this.childRoot;
			_child.objectInfo.changeAmount.pos = _child.guideObject.transformTarget.localPosition;
			_child.objectInfo.changeAmount.rot = _child.guideObject.transformTarget.localEulerAngles;
			_child.parentInfo = this;
		}

		// Token: 0x06001D42 RID: 7490 RVA: 0x000BA6C0 File Offset: 0x000B88C0
		public override void OnLoadAttach(TreeNodeObject _parent, ObjectCtrlInfo _child)
		{
			if (_child.parentInfo == null)
			{
				Studio.DeleteInfo(_child.objectInfo, false);
			}
			else
			{
				_child.parentInfo.OnDetachChild(_child);
			}
			if (!this.itemInfo.child.Contains(_child.objectInfo))
			{
				this.itemInfo.child.Add(_child.objectInfo);
			}
			_child.guideObject.transformTarget.SetParent(this.childRoot, false);
			_child.guideObject.parent = this.childRoot;
			_child.objectInfo.changeAmount.OnChange();
			_child.parentInfo = this;
		}

		// Token: 0x06001D43 RID: 7491 RVA: 0x000BA768 File Offset: 0x000B8968
		public override void OnDetach()
		{
			this.parentInfo.OnDetachChild(this);
			this.guideObject.parent = null;
			Studio.AddInfo(this.objectInfo, this);
			this.objectItem.transform.SetParent(Singleton<Scene>.Instance.commonSpace.transform);
			this.objectInfo.changeAmount.pos = this.objectItem.transform.localPosition;
			this.objectInfo.changeAmount.rot = this.objectItem.transform.localEulerAngles;
			this.guideObject.calcMode = GuideObject.Mode.Local;
		}

		// Token: 0x06001D44 RID: 7492 RVA: 0x000BA804 File Offset: 0x000B8A04
		public override void OnSelect(bool _select)
		{
			int layer = LayerMask.NameToLayer((!_select) ? "Studio/Select" : "Studio/Col");
			if (!this.listBones.IsNullOrEmpty<OCIChar.BoneInfo>())
			{
				foreach (OCIChar.BoneInfo boneInfo in this.listBones)
				{
					boneInfo.layer = layer;
				}
			}
		}

		// Token: 0x06001D45 RID: 7493 RVA: 0x000BA88C File Offset: 0x000B8A8C
		public override void OnDetachChild(ObjectCtrlInfo _child)
		{
			if (!this.itemInfo.child.Remove(_child.objectInfo))
			{
				GlobalData.Debug_LogError("信息删除失败");
			}
			_child.parentInfo = null;
		}

		// Token: 0x06001D46 RID: 7494 RVA: 0x000BA8BC File Offset: 0x000B8ABC
		public override void OnSavePreprocessing()
		{
			base.OnSavePreprocessing();
			if (this.isAnime && this.animator.layerCount != 0)
			{
				AnimatorStateInfo currentAnimatorStateInfo = this.animator.GetCurrentAnimatorStateInfo(0);
				this.itemInfo.animeNormalizedTime = currentAnimatorStateInfo.normalizedTime;
			}
		}

		// Token: 0x1700030E RID: 782
		// (get) Token: 0x06001D47 RID: 7495 RVA: 0x000BA90C File Offset: 0x000B8B0C
		// (set) Token: 0x06001D48 RID: 7496 RVA: 0x000BA91C File Offset: 0x000B8B1C
		public override float animeSpeed
		{
			get
			{
				return this.itemInfo.animeSpeed;
			}
			set
			{
				if (Utility.SetStruct<float>(ref this.itemInfo.animeSpeed, value) && this.animator)
				{
					this.animator.speed = this.itemInfo.animeSpeed;
				}
			}
		}

		// Token: 0x06001D49 RID: 7497 RVA: 0x000BA95C File Offset: 0x000B8B5C
		public override void OnVisible(bool _visible)
		{
			this.visible = _visible;
		}

		// Token: 0x06001D4A RID: 7498 RVA: 0x000BA968 File Offset: 0x000B8B68
		public void SetColor(Color _color)
		{
			this.itemInfo.color.SetDiffuseRGBA(_color);
			this.UpdateColor();
		}

		// Token: 0x06001D4B RID: 7499 RVA: 0x000BA984 File Offset: 0x000B8B84
		public void SetGloss(Color _color)
		{
			this.itemInfo.color.SetSpecularRGB(_color);
			this.UpdateColor();
		}

		// Token: 0x06001D4C RID: 7500 RVA: 0x000BA9A0 File Offset: 0x000B8BA0
		public bool SetIntensity(float _value)
		{
			bool flag = Utility.SetStruct<float>(ref this.itemInfo.color.specularIntensity, Mathf.Clamp01(_value));
			if (flag)
			{
				this.UpdateColor();
			}
			return flag;
		}

		// Token: 0x06001D4D RID: 7501 RVA: 0x000BA9D8 File Offset: 0x000B8BD8
		public bool SetSharpness(float _value)
		{
			bool flag = Utility.SetStruct<float>(ref this.itemInfo.color.specularSharpness, Mathf.Clamp01(_value));
			if (flag)
			{
				this.UpdateColor();
			}
			return flag;
		}

		// Token: 0x06001D4E RID: 7502 RVA: 0x000BAA10 File Offset: 0x000B8C10
		public void SetColor2(Color _color)
		{
			this.itemInfo.color2.SetDiffuseRGBA(_color);
			this.UpdateColor();
		}

		// Token: 0x06001D4F RID: 7503 RVA: 0x000BAA2C File Offset: 0x000B8C2C
		public void SetGloss2(Color _color)
		{
			this.itemInfo.color2.SetSpecularRGB(_color);
			this.UpdateColor();
		}

		// Token: 0x06001D50 RID: 7504 RVA: 0x000BAA48 File Offset: 0x000B8C48
		public bool SetSharpness2(float _value)
		{
			bool flag = Utility.SetStruct<float>(ref this.itemInfo.color2.specularSharpness, Mathf.Clamp01(_value));
			if (flag)
			{
				this.UpdateColor();
			}
			return flag;
		}

		// Token: 0x06001D51 RID: 7505 RVA: 0x000BAA80 File Offset: 0x000B8C80
		public void UpdateColor()
		{
			if (this.colorTargets.IsNullOrEmpty<OCIItem.ColorTargetInfo>())
			{
				return;
			}
			for (int i = 0; i < this.colorTargets.Length; i++)
			{
				ColorChange.SetHSColor(this.colorTargets[i].material, this.itemInfo.color, !this.colorTargets[i].isColor2Only, !this.colorTargets[i].isColor2Only, (!this.colorTargets[i].isColor2) ? null : this.itemInfo.color2, true, true);
			}
		}

		// Token: 0x06001D52 RID: 7506 RVA: 0x000BAB1C File Offset: 0x000B8D1C
		public void ActiveFK(bool _active)
		{
			if (this.itemFKCtrl == null)
			{
				return;
			}
			this.itemFKCtrl.enabled = _active;
			this.itemInfo.enableFK = _active;
			foreach (DynamicBone dynamicBone in this.dynamicBones)
			{
				dynamicBone.enabled = !_active;
			}
			foreach (OCIChar.BoneInfo boneInfo in this.listBones)
			{
				boneInfo.active = _active;
			}
		}

		// Token: 0x06001D53 RID: 7507 RVA: 0x000BABCC File Offset: 0x000B8DCC
		public void RestartAnime()
		{
			if (!this.isAnime)
			{
				return;
			}
			if (this.animator.layerCount == 0)
			{
				return;
			}
			AnimatorStateInfo currentAnimatorStateInfo = this.animator.GetCurrentAnimatorStateInfo(0);
			this.animator.Play(currentAnimatorStateInfo.shortNameHash, 0, 0f);
		}

		// Token: 0x04001FB2 RID: 8114
		public GameObject objectItem;

		// Token: 0x04001FB3 RID: 8115
		public Transform childRoot;

		// Token: 0x04001FB4 RID: 8116
		public Animator animator;

		// Token: 0x04001FB5 RID: 8117
		public OCIItem.ColorTargetInfo[] colorTargets;

		// Token: 0x04001FB6 RID: 8118
		public ItemFKCtrl itemFKCtrl;

		// Token: 0x04001FB7 RID: 8119
		public List<OCIChar.BoneInfo> listBones;

		// Token: 0x04001FB8 RID: 8120
		public DynamicBone[] dynamicBones;

		// Token: 0x04001FB9 RID: 8121
		private bool m_Visible = true;

		// Token: 0x04001FBA RID: 8122
		public Renderer[] arrayRender;

		// Token: 0x04001FBB RID: 8123
		public ParticleSystem[] arrayParticle;

		// Token: 0x02000497 RID: 1175
		public class ColorTargetInfo
		{
			// Token: 0x06001D55 RID: 7509 RVA: 0x000BAC34 File Offset: 0x000B8E34
			public ColorTargetInfo(Renderer _renderer)
			{
				this.renderer = _renderer;
			}

			// Token: 0x1700030F RID: 783
			// (get) Token: 0x06001D56 RID: 7510 RVA: 0x000BAC44 File Offset: 0x000B8E44
			public Material material
			{
				get
				{
					return this.renderer.material;
				}
			}

			// Token: 0x04001FBD RID: 8125
			public Renderer renderer;

			// Token: 0x04001FBE RID: 8126
			public bool isColor2;

			// Token: 0x04001FBF RID: 8127
			public bool isColor2Only;
		}
	}
}
